<!doctype html><html xmlns="http://www.w3.org/1999/xhtml" id="html">
    <head>
        <title></title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <base href="<?= base_url(1); ?>" />
        <link type="text/css" href="css/main.css?v=<?= $config['version'] ?>" rel="stylesheet" />
        <style type="text/css">
            <?php if ($row['rank'] < 50 || $row['rank'] == 100) { ?>#per {display:none;}<?php } ?>
            .per {clear:both;display:block;padding:5px 0;border-bottom:1px solid #ccc;}
            .per input {margin-right:3px;vertical-align: middle}
            .per dt {width:100px;float: left;}
            .per dd {width:370px;float: right;margin:3px 0}
            .per dd h3{width:100px;float: left;}
            .per dd ul{width:260px;float: left;}
            .per dd ul li{float: left;margin-right:5px;}
        </style>
    </head>
    <body>
        <?php include(VIEWPATH . 'common/main_header.php'); ?>
        <form action="" method="POST" id="rowForm">
            <table width="100%" border="0" cellspacing="1" cellpadding="0" class="tablegrid tableedit">
                <tr>
                    <td><?= translate('ROLE_ROLE_NAME') ?>:</td>
                    <td><input type="text" name="row[name]" id="name" value="<?= $row['name']; ?>" /></td>
                </tr>
                <?php if ($row['id'] != '5c7ace4a-b3bf-4734-9afd-6bda7ed9b964') { ?>
                    <tr>
                        <td><?= translate('ROLE_ROLE_RANK') ?>:</td>
                        <td><input type="text" name="row[rank]" id="rank" maxlength="3" value="<?= $row['rank']; ?>" <?php echo $row['rank'] == 100 && $row['id'] == 1 ? 'readonly' : '' ?> /></td>
                    </tr>
                    <tr>
                        <td><?= translate('ROLE_ROLE_FATHER_ID') ?>:</td>
                        <td>
                            <?= $row['rolelist'] ?>
                        </td>
                    </tr>
                    <?php if (check_level_menu(100)) { ?>
                        <tr>
                            <td><?= translate('ROLE_ROLE_ALLOW_URL') ?>:</td>
                            <td><textarea name="row[allow_uri]" id="allow_uri" cols="50" rows="5"><?= $row['allow_uri']; ?></textarea></td>
                        </tr>
                        <tr>
                            <td><?= translate('ROLE_ROLE_DENY_URL') ?>:</td>
                            <td><textarea name="row[deny_uri]" id="deny_uri" cols="50" rows="5"><?= $row['deny_uri']; ?></textarea></td>
                        </tr>
                    <?php } ?>
                    <tr id="per">
                        <td><?= translate('ROLE_ROLE_PERMISSION') ?>:</td>
                        <td>
                            <?php foreach ($permission as $m => $n) { ?>
                                <?php if (check_level_menu($user['role_rank'], $m)) { ?>
                                    <dl class="per clear">
                                        <dt><input type="checkbox" name="row[permission][]" class="first" value="<?= $m ?>" id="c-<?= $m ?>" <?= checkinarray($m, $row['admin']) ?> /><label for="c-<?= $m ?>"><?= $n['name'] ?></label></dt>
                                        <?php foreach ($n['item'] as $u => $v) { ?>
                                            <?php if (check_level_menu($user['role_rank'], $m, $u)) { ?>
                                                <dd<?php if (!isset($v['item']) && !in_array($m, array('general', 'user'))) { ?> style="float:left;width:50px;"<?php } ?>>
                                                    <h3><input type="checkbox" name="row[permission][<?= $m ?>][]" class="second" value="<?= $u ?>" id="c-<?= $m ?>-<?= $u ?>" <?= isset($row['admin'][$m]) ? checkinarray($u, $row['admin'][$m]) : '' ?> /><label for="c-<?= $m ?>-<?= $u ?>"><?= $v['name'] ?></label></h3>
                                                    <ul>
                                                        <?php if (isset($v['item'])) { ?>
                                                            <?php foreach ($v['item'] as $x => $y) { ?>
                                                                <?php if (check_level_menu($user['role_rank'], $m, $u, $x)) { ?>
                                                                    <li><input type="checkbox" name="row[permission][<?= $m ?>][<?= $u ?>][]" class="third" value="<?= $x ?>" id="c-<?= $m ?>-<?= $u ?>-<?= $x ?>" <?= isset($row['admin'][$m][$u]) ? checkinarray($x, $row['admin'][$m][$u]) : '' ?>/><label for="c-<?= $m ?>-<?= $u ?>-<?= $x ?>"><?= $y ?></label></li>
                                                                <?php } ?>
                                                            <?php } ?>
                                                        <?php } ?>
                                                    </ul>
                                                </dd>
                                            <?php } ?>
                                        <?php } ?>
                                    </dl>
                                <?php } ?>
                            <?php } ?>
                        </td>
                    </tr>
                <?php } ?>
                <tr>
                    <td><?= translate('SYNC') ?>:</td>
                    <td><?= $arealist ?></td>
                </tr>
                <tr><td></td>
                    <td>
                        <input type="submit" value="<?= translate('SUBMIT') ?>" id="submit"/> <input type="reset" value="<?= translate('RESET') ?>" id="reset"/>
                    </td>
                </tr>
            </table>
        </form>
        <script type="text/javascript">
            SG.init("core.form", function() {
                $.formValidator.initConfig({formid: "#rowForm", submitonce: true});
                $("#name").formValidator({empty: false, onshow: '<?= translate('C_NOT_EMPTY') ?>'}).inputValidator({min: 1, onerrormin: '<?= translate('C_NOT_EMPTY') ?>'});
                $("#rank").formValidator({empty: false, onshow: '<?php if ($user['role_rank'] == 100) { ?>100:<?= translate('ROLE_SUPER_ADMIN') ?>,<?php } ?><?= translate('ROLE_ROLE_FORM_INPUT_RANK_SHOW_SMALL_THAN', $user['role_rank']) ?>'}).regexValidator({regexp: 'num', datatype: 'enum', onerror: '<?= translate('C_ONLY_NUM') ?>'}).inputValidator({type: 'number', min: 0, max:<?= $user['role_rank'] ?>, onerror: '<?= translate('ROLE_ROLE_FORM_INPUT_RANK_ERROR_SMALL_THAN', $user['role_rank']) ?>'});
            });
            $(function() {
                $("#rank").bind("keyup", function() {
                    if (parseFloat($(this).val()) >= 50 && parseFloat($(this).val()) <=<?= $user['role_rank'] ?>) {
                        $("#per").show();
                    } else {
                        $("#per").hide();
                        $("#per input[type=checkbox]").attr("checked", "");
                    }
                });

                $(".first").change(function() {
                    if ($(this).attr("checked") == true) {
                        $(this).parent().siblings("dd").find("input").attr("checked", "checked");
                    } else {
                        $(this).parent().siblings("dd").find("input").attr("checked", "");
                    }
                });
                $(".second").change(function() {
                    if ($(this).attr("checked") == true) {
                        $(this).parent().parent().prevAll("dt").find("input").attr("checked", "checked");
                        $(this).parent().next().find("input").attr("checked", "checked");
                    } else {
                        $(this).parent().next().find("input").attr("checked", "");
                        if ($(this).parents(".per").find("dd .second:checked").length == 0) {
                            $(this).parents(".per").find("dt input").attr("checked", "");
                        }
                    }
                });
                $(".third").change(function() {
                    if ($(this).attr("checked") == true) {
                        $(this).parent().parent().prev().find("input").attr("checked", "checked").change();
                    } else {
                        if ($(this).parents("ul").find("input:checked").length == 0) {
                            $(this).parents("ul").prev().find("input").attr("checked", "").change();
                        }
                    }
                });
            });
        </script>
    </body>
</html>